package com.mybatis.plugin;

import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Properties;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-24 15:17:30
 */
@Intercepts({
        // insert update delete
        @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})
})
public class ResultSetHandlerHandler1 implements Interceptor {

    public ResultSetHandlerHandler1() {
    }

    public ResultSetHandlerHandler1(String id) {

    }

    private static final Logger logger = LoggerFactory.getLogger(ResultSetHandlerHandler1.class);

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Method method = invocation.getMethod();
        Object[] args = invocation.getArgs();
        Object target = invocation.getTarget();
        logger.info("method = {}, args = {}, target = {}",
                method, Arrays.toString(args), target);

        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
